package 动态规划;

import java.util.Set;

//https://www.nowcoder.com/practice/5f3b7bf611764c8ba7868f3ed40d6b2c?tpId=46&tqId=29041&tPage=1&rp=1&ru=/ta/leetcode&qru=/ta/leetcode/question-ranking
public class 拆分词句 {
    public boolean wordBreak(String s, Set<String> dict) {
        boolean[] dp = new boolean[s.length() + 1];
        dp[0] = true;
        for (int i = 1; i <= s.length(); i++) {
            for (int j = i - 1; j >= 0 ; j--) {
                if (dp[j] == true && dict.contains(s.substring(j , i))){
                    dp[i] = true;
                }
            }
        }
        return dp[s.length()];
    }
}
